using System.Text.Json.Serialization;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs.Common;

/// <summary>
/// 批量删除操作结果
/// </summary>
public class BatchDeleteResult
{
    /// <summary>
    /// 成功删除的数量
    /// </summary>
    /// <example>5</example>
    [JsonPropertyName("successCount")]
    public int SuccessCount { get; set; }

    /// <summary>
    /// 删除失败的数量
    /// </summary>
    /// <example>2</example>
    [JsonPropertyName("failCount")]
    public int FailCount { get; set; }

    /// <summary>
    /// 总数量
    /// </summary>
    /// <example>7</example>
    [JsonPropertyName("totalCount")]
    public int TotalCount { get; set; }

    /// <summary>
    /// 成功删除的项目ID列表
    /// </summary>
    /// <example>[1, 2, 3, 4, 5]</example>
    [JsonPropertyName("successIds")]
    public List<long> SuccessIds { get; set; } = new();

    /// <summary>
    /// 删除失败的项目详情
    /// </summary>
    [JsonPropertyName("failures")]
    public List<BatchDeleteFailure> Failures { get; set; } = new();

    /// <summary>
    /// 是否全部成功
    /// </summary>
    /// <example>false</example>
    [JsonPropertyName("allSuccessful")]
    public bool AllSuccessful => FailCount == 0;
}

/// <summary>
/// 批量删除失败详情
/// </summary>
public class BatchDeleteFailure
{
    /// <summary>
    /// 失败项目的ID
    /// </summary>
    /// <example>6</example>
    [JsonPropertyName("id")]
    public long Id { get; set; }

    /// <summary>
    /// 失败原因
    /// </summary>
    /// <example>该项目包含子项目，无法删除</example>
    [JsonPropertyName("reason")]
    public string Reason { get; set; } = string.Empty;

    /// <summary>
    /// 错误码
    /// </summary>
    /// <example>3004</example>
    [JsonPropertyName("errorCode")]
    public string? ErrorCode { get; set; }
}
